<?php

/**
 * This is the model class for table "buronan".
 *
 * The followings are the available columns in table 'buronan':
 * @property integer $id
 * @property string $nama
 * @property string $tempat_lahir
 * @property string $tanggal_lahir
 * @property string $kelamin
 * @property string $tempat_tinggal
 * @property string $agama
 * @property string $warganegara
 * @property string $ciri_fisik
 * @property string $kejahatan
 * @property string $keterangan_tambahan
 * @property integer $created_by
 * @property string $created_time
 * @property integer $updated_by
 * @property string $updated_time
 */
class Buronan extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'buronan';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('nama, kelamin, tempat_tinggal, warganegara, ciri_fisik, kejahatan', 'required'),
			array('tampil,created_by, updated_by', 'numerical', 'integerOnly'=>true),
			array('photo, nama, tempat_tinggal', 'length', 'max'=>200),
			array('tempat_lahir, warganegara', 'length', 'max'=>100),
			array('kelamin', 'length', 'max'=>1),
			array('agama', 'length', 'max'=>20),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('photo, tampil, id, nama, tempat_lahir, tanggal_lahir, kelamin, tempat_tinggal, agama, warganegara, ciri_fisik, kejahatan, keterangan_tambahan, created_by, created_time, updated_by, updated_time', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'nama' => 'Nama',
			'tempat_lahir' => 'Tempat Lahir',
			'tanggal_lahir' => 'Tanggal Lahir',
			'kelamin' => 'Jenis Kelamin',
			'tempat_tinggal' => 'Tempat Tinggal',
			'agama' => 'Agama',
			'warganegara' => 'Kewarganegaraan',
			'ciri_fisik' => 'Ciri Fisik',
			'kejahatan' => 'Kejahatan',
			'keterangan_tambahan' => 'Keterangan Tambahan',
			'created_by' => 'Created By',
			'created_time' => 'Created Time',
			'updated_by' => 'Updated By',
			'updated_time' => 'Updated Time',
			'tampil' => 'Tampilkan',
			'photo' => 'Foto',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('nama',$this->nama,true);
		$criteria->compare('tempat_lahir',$this->tempat_lahir,true);
		$criteria->compare('tanggal_lahir',$this->tanggal_lahir,true);
		$criteria->compare('kelamin',$this->kelamin,true);
		$criteria->compare('tempat_tinggal',$this->tempat_tinggal,true);
		$criteria->compare('agama',$this->agama,true);
		$criteria->compare('warganegara',$this->warganegara,true);
		$criteria->compare('ciri_fisik',$this->ciri_fisik,true);
		$criteria->compare('kejahatan',$this->kejahatan,true);
		$criteria->compare('keterangan_tambahan',$this->keterangan_tambahan,true);
		$criteria->compare('created_by',$this->created_by);
		$criteria->compare('created_time',$this->created_time,true);
		$criteria->compare('updated_by',$this->updated_by);
		$criteria->compare('updated_time',$this->updated_time,true);
		$criteria->compare('tampil',$this->tampil,true);
		$criteria->compare('photo',$this->photo,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}


	public function search2()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;
		$criteria->condition = 'tampil=1';

		$criteria->compare('id',$this->id);
		$criteria->compare('nama',$this->nama,true);
		$criteria->compare('tempat_lahir',$this->tempat_lahir,true);
		$criteria->compare('tanggal_lahir',$this->tanggal_lahir,true);
		$criteria->compare('kelamin',$this->kelamin,true);
		$criteria->compare('tempat_tinggal',$this->tempat_tinggal,true);
		$criteria->compare('agama',$this->agama,true);
		$criteria->compare('warganegara',$this->warganegara,true);
		$criteria->compare('ciri_fisik',$this->ciri_fisik,true);
		$criteria->compare('kejahatan',$this->kejahatan,true);
		$criteria->compare('keterangan_tambahan',$this->keterangan_tambahan,true);
		$criteria->compare('created_by',$this->created_by);
		$criteria->compare('created_time',$this->created_time,true);
		$criteria->compare('updated_by',$this->updated_by);
		$criteria->compare('updated_time',$this->updated_time,true);
		$criteria->compare('tampil',$this->tampil,true);
		$criteria->compare('photo',$this->photo,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}


	public function findKelamin($kelamin){
		if($kelamin=='l'){
			echo 'Laki-Laki';
		}
		else{
			echo 'Perempuan';
		}
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Buronan the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
